<?php
class ORMCustomer extends ORMBase {
  public function __construct() {
    parent::__construct('Customer');
  }

  public function __toEpObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMCustomerContact.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrder.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $epObject->trackId = isset($object->trackId) ? $object->trackId : '';
    $epObject->createdDate = (isset($object->createdDate) && $object->createdDate) ? SimpleDate::toStamp($object->createdDate) : 0;
    if (isset($object->sales) && $object->sales) {
        $epObject->sales = $this->__getEpObject_4_lvl_1_object($myManager, $object->sales, new ORMUser(), 'User');
    } else {
      if (isset($epObject->sales)) {
        $myManager->delete($epObject->sales);
      }
    }
    if (isset($object->bride) && $object->bride) {
        $epObject->bride = $this->__getEpObject_4_lvl_1_object($myManager, $object->bride, new ORMCustomerContact(), 'CustomerContact');
    } else {
      if (isset($epObject->bride)) {
        $myManager->delete($epObject->bride);
      }
    }
    if (isset($object->groom) && $object->groom) {
        $epObject->groom = $this->__getEpObject_4_lvl_1_object($myManager, $object->groom, new ORMCustomerContact(), 'CustomerContact');
    } else {
      if (isset($epObject->groom)) {
        $myManager->delete($epObject->groom);
      }
    }
    $epObject->note = isset($object->note) ? $object->note : '';
    $epObject->ceremony = isset($object->ceremony) ? $object->ceremony : '';
    $epObject->culture = isset($object->culture) ? $object->culture : '';
    $epObject->culture2 = isset($object->culture2) ? $object->culture2 : '';
    $epObject->reception = isset($object->reception) ? $object->reception : '';
    $epObject->source = isset($object->source) ? $object->source : '';
    if (isset($epObject->orders)) {
      $epObject->orders->removeAll();
      foreach ($object->orders as &$item) {
        $epObject->orders[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMMyOrder(), 'MyOrder');
      }
    }
    $epObject->userAccount = isset($object->userAccount) ? $object->userAccount : '';
    $epObject->reminderNote = isset($object->reminderNote) ? $object->reminderNote : '';
    $epObject->cancelled = isset($object->cancelled) ? $object->cancelled : 0;
    $epObject->cancelledDate = (isset($object->cancelledDate) && $object->cancelledDate) ? SimpleDate::toStamp($object->cancelledDate) : 0;
    $epObject->cancelledOperator = isset($object->cancelledOperator) ? $object->cancelledOperator : '';
    $epObject->cancelledMessage = isset($object->cancelledMessage) ? $object->cancelledMessage : '';
    $epObject->admAppr = isset($object->admAppr) ? $object->admAppr : 0;
    return $epObject;
  }

  public function __toObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMCustomerContact.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrder.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $object->id = $epObject->oid;
    $object->trackId = $epObject->trackId;
    $object->createdDate = ($epObject->createdDate != 0) ? SimpleDate::fromStamp($epObject->createdDate) : 0;
    if (isset($epObject->sales)) {
      $object->sales = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->sales, new ORMUser());
    }
    if (isset($epObject->bride)) {
      $object->bride = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->bride, new ORMCustomerContact());
    }
    if (isset($epObject->groom)) {
      $object->groom = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->groom, new ORMCustomerContact());
    }
    $object->note = $epObject->note;
    $object->ceremony = $epObject->ceremony;
    $object->culture = $epObject->culture;
    $object->culture2 = $epObject->culture2;
    $object->reception = $epObject->reception;
    $object->source = $epObject->source;
    $object->orders = array();
    if (isset($epObject->orders)) {
      foreach ($epObject->orders as &$item) {
        $object->orders[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMMyOrder());
      }
    }
    $object->userAccount = $epObject->userAccount;
    $object->reminderNote = $epObject->reminderNote;
    $object->cancelled = $epObject->cancelled;
    $object->cancelledDate = ($epObject->cancelledDate != 0) ? SimpleDate::fromStamp($epObject->cancelledDate) : 0;
    $object->cancelledOperator = $epObject->cancelledOperator;
    $object->cancelledMessage = $epObject->cancelledMessage;
    $object->admAppr = $epObject->admAppr;
    return $object;
  }
}
?>
